<?php

class Nimblecms_Form_Decorator_Tinymce extends Zend_Form_Decorator_Abstract {
	
	private function getTinymce($id) {
		$html = '<script type="text/javascript" src="/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>';
		$html .= '<script type="text/javascript">';
		$html .= 'tinyMCE.init({mode:"exact",elements:"'.$id.'",skin:"o2k7",theme:"advanced",theme_advanced_toolbar_location:"top",theme_advanced_resizing:true,theme_advanced_statusbar_location:"bottom"});';
		$html .= '</script>';
		return $html;
	}
	
	public function render($content) {
		$element = $this->getElement ();
		if (! $element instanceof Zend_Form_Element) {
			return $content;
		}
		
		if (null === $element->getView ()) {
			return $content;
		}
		
		
		
		$placement = $this->getPlacement ();
		
		$separator = $this->getSeparator ();
		
		$id = $element->getAttrib('id');
		switch ($placement) {
			case 'APPEND' :
				return $this->getTinymce ($id) . $content . $separator;
			case 'PREPEND' :
				return $this->getTinymce ($id) . $separator . $content;
			case null :
			
			default :
				return $this->getTinymce ($id) . $separator . $content;
		}
	}
}